package com.idopartx.phonelightning.viewmodel

import android.graphics.Color
import android.graphics.Path
import androidx.lifecycle.MutableLiveData
import androidx.lifecycle.ViewModel
import com.idopartx.phonelightning.common.Constant
import com.idopartx.phonelightning.entity.ScreenLightningEntity
import com.tencent.mmkv.MMKV

class ScreenViewModel : ViewModel() {
    fun init() {

        val screenCache = MMKV.defaultMMKV().decodeParcelable(
            Constant.MMKV_SAVE_SCREEN_LIGHTNING,
            ScreenLightningEntity::class.java
        )

        directionLiveData.value = screenCache?.direction ?: Path.Direction.CCW
        isOpenLiveData.value = screenCache?.isOpen ?: true
        typeLiveData.value = if (screenCache != null) screenCache.type else 0
        colorLiveData.value =
            if (screenCache != null && screenCache.color != 0) screenCache.color else Color.parseColor(
                "#F32400"
            )
        xLiveData.value = screenCache?.x ?: 0
        yLiveData.value = screenCache?.y ?: 0
        widthLiveData.value = if (screenCache != null) screenCache.width else 1
        lengthLiveData.value = if (screenCache != null) screenCache.length else 1
        speedLiveData.value = if (screenCache != null) screenCache.speed else 1
    }


    val directionLiveData: MutableLiveData<Path.Direction> by lazy {
        MutableLiveData()
    }
    val typeLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val widthLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val lengthLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val speedLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val colorLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val xLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }
    val yLiveData: MutableLiveData<Int> by lazy {
        MutableLiveData()
    }

    val isOpenLiveData: MutableLiveData<Boolean> by lazy {
        MutableLiveData()
    }

}